<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head th:include="common">
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <button class="btn btn-success" onclick="openAddDialog()">新增</button>
    <div class="modal fade" id="addDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                    <h4 class="modal-title" id="myModalLabel">详情</h4>
                </div>
                <div class="modal-body">
                    <form id="addForm" action="<%=path%>/erp/addComm.do" method="post">
                        <div class="form-group">
                            <label for="cname">商品id</label>
                            <input type="text" name="goodsId" class="form-control" id="cname" readonly>
                        </div>
                        <div class="form-group">
                            <label for="cname">商品名称</label>
                            <input type="text" name="goodsName" class="form-control" id="cname" placeholder="商品名称">
                        </div>
                        <div class="form-group">
                            <label for="csourcePrice">地址</label>
                            <input type="text" name="goodsAdress" class="form-control" id="csourcePrice" >
                        </div>
                        <!--<div class="form-group">
                            <label for="csourcePrice">开始时间</label>
                            <input type="date" name="goodsStartTime" class="form-control" >
                        </div>
                        <div class="form-group">
                            <label for="csourcePrice">结束时间</label>
                            <input type="date" name="goodsEndTime" class="form-control"  >
                        </div>-->
                        <div class="form-group city">
                            <label for="ctype">城市</label>
                            <select name="goodsCityId" id="addidCity">
                            </select>
                        </div>
                        <div class="form-group type">
                            <label for="ctype">类型</label>
                            <select name="goodsTypeId" id="addidType">
                            </select>
                        </div>
                        <div class="form-group active">
                            <label for="ctype">系列活动</label>
                            <select name="goodsActivityNumber" id="addidActive">
                            </select>
                        </div>
                        <div class="form-group" id="addCheckBox">
                            <label for="ccount">配送方式</label>
                        </div>
                        <div class="form-group">
                            <label for="ccount">总票数</label>
                            <input type="text" name="goodsTicketsVendibilityCount" class="form-control"  >
                        </div>
                        <div class="form-group">
                            <label for="ccount">主要演员</label>
                            <input type="text" name="goodsMainActor" class="form-control"  >
                        </div>
                        <div class="form-group">
                            <label for="ccount">推荐度</label>
                            <input type="text" name="goodsRecommendedDegree" class="form-control" >
                        </div>
                        <div class="form-group radi">
                            <input type="radio" name="goodsUndeterminedActive" value="1">待定
                            <input type="radio" name="goodsUndeterminedActive" value="2">非待定
                        </div>
                        <div class="form-group">
                            <button type="button" class="btn btn-success" onclick="openImg()">图片</button>
                            <label for="cimg">图片</label>
                            <div class="modal fade" id="imgDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                <div class="modal-dialog" role="document" >
                                    <div class="modal-content" style="width:400px">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                                            <h4 class="modal-title" id="myModalLabel">上传</h4>
                                        </div>
                                        <div class="modal-body">
                                            <input id="filePortrait" type="file" name="imgfile"/>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭</button>
                                            <button type="button" id="btn_submit" class="btn btn-primary" alert="submitFrorm()"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <input type="text" name="goodsImg" class="form-control" id="cimg" placeholder="图片">
                        </div>
                        <!--添加场次-->
                        <button type="button" class="btn btn-success" onclick="addGoodsSession()">添加</button>
                        <div id="ronda"></div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" id="btn_submit" onclick="addGoods()">保存</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭</button>
                </div>
            </div>
        </div>
    </div>
</body>
<script>
    //打开新增

    $("#addDialog").modal();
    //王乐城市动态下拉
    $.ajax({
        url:"/goodsConsummer/getCitySelect",
        async:false,
        success:function(data){
            var str="";
            str+="<option value='0'>请选择</option>";
            for (var i = 0; i < data.length; i++) {
                str+="<option value='"+data[i].cityId+"'>"+data[i].cityName+"</option>"
            }
            $("#addidCity").append(str);
            $("#addidCity").selectpicker("refresh");
        }
    })
    //类型动态下拉
    $.ajax({
        url:"/goodsConsummer/getTypeSelect",
        async:false,
        success:function(data){
            var str="";
            str+="<option value='0'>请选择</option>";
            for (var i = 0; i < data.length; i++) {
                str+="<option value='"+data[i].goodsTypeId+"'>"+data[i].goodsTypeName+"</option>"
            }
            $("#addidType").append(str);
            $("#addidType").selectpicker("refresh");
        }
    })
    //系列活动动态下拉
    $.ajax({
        url:"/goodsConsummer/getActiveSelect",
        async:false,
        success:function(data){
            var str="";
            str+="<option value='0'>请选择</option>";
            for (var i = 0; i < data.length; i++) {
                str+="<option value='"+data[i].activityId+"'>"+data[i].activityName+"</option>"
            }
            $("#addidActive").append(str);
            $("#addidActive").selectpicker("refresh");
        }
    })
    //查询配送方式
        $.ajax({
            url:"/goodsConsummer/getDistr/",
            data:{},
            success:function(data){
                console.log(data)
                $("#addCheckBox").append(data);
            }
        })

    var i=0;
    //添加场次
    function addGoodsSession(){
        var str = "";
        str+="++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>"
            +"开始时间<input type='date' name='goodsSessionEntityList["+i+"].sessionTime' ><br>"
            +"结束时间<input type='date' name='goodsSessionEntityList["+i+"].endTime' ><br>"
            +"场次描述<input name='goodsSessionEntityList["+i+"].onlineDescription' ><br>"
        var str2='';
        str2+='<button type="button"  className="btn btn-success" onClick="addGoodsLeave('+i+')">添加档次</button></br>'
                +'<div id="goodsLeave'+i+'"></div>'
        $("#ronda").append(str);
        $("#ronda").append(str2);
        //定义动态全局变量
        var names='j'+i;
    //  alert(names)
        window[names]=0;
     // alert(window['j'+i]);
        i++;
    }
    //添加档次
    function addGoodsLeave(i){
        //alert(i)
        var str = "";
        str+="\t档次名<input name='goodsSessionEntityList["+i+"].goodsLeaveList["+window['j'+i]+"].leaveName' ><br>"
            +"\t该档次的商品售价<input name='goodsSessionEntityList["+i+"].goodsLeaveList["+window['j'+i]+"].goodsPrice' ><br>"
            +"\t总票数<input name='goodsSessionEntityList["+i+"].goodsLeaveList["+window['j'+i]+"].goodsCount' ><br>"
            +"\t出售量<input name='goodsSessionEntityList["+i+"].goodsLeaveList["+window['j'+i]+"].soldCount' ><br>"
            +"\t档次描述<input name='goodsSessionEntityList["+i+"].goodsLeaveList["+window['j'+i]+"].leaveInfo' ><br>"
            +"\t成本价格<input name='goodsSessionEntityList["+i+"].goodsLeaveList["+window['j'+i]+"].truePrice' ><br>"
            +"---------------------------------------------------------------------<br>"
        window['j'+i]++;
        $("#goodsLeave"+i).append(str);
    }
    //图片
    function openImg(){
        $('#imgDialog').modal();
    }

    //初始化fileinput控件（第一次初始化）
    $('#filePortrait').fileinput({
        language: 'zh', //设置语言
        uploadUrl: "/goodsConsummer/upload", //上传的地址
        allowedFileExtensions : ['jpg', 'png','gif'],//接收的文件后缀,
        maxFileCount: 100,
        enctype: 'multipart/form‐data',
        showUpload: true, //是否显示上传按钮
        showCaption: false,//是否显示标题
        browseClass: "btn btn‐primary", //按钮样式
        previewFileIcon: "<i class='glyphicon glyphicon‐king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",

        //dropZoneEnabled: false,//是否显示拖拽区域
        //minImageWidth: 50, //图片的最小宽度
        //minImageHeight: 50,//图片的最小高度
        //maxImageWidth: 1000,//图片的最大宽度
        //maxImageHeight: 1000,//图片的最大高度
        //maxFileSize: 0,//单位为kb，如果为0表示不限制文件大小
        //minFileCount: 0,
        // maxFileCount: 10, //表示允许同时上传的最大文件个数
        // enctype: 'multipart/form‐data',
        // validateInitialCount:true,24 // previewFileIcon: "<i class='glyphicon glyphicon‐king'></i>",
        // msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
    })
    //导入文件上传完成之后的事件
    $("#filePortrait").on("fileuploaded", function (event, data, previewId, index) {
        console.log(data.response);
        console.log(data.response.requestPath);
        $("#cimg").val(data.response.url);
        $('#imgDialog').modal('hide');
    });



    //新增
    function  addGoods(){
        $.ajax({
            url:"/goodsConsummer/addGoods",
            data:$("#addForm").serialize(),
            success:function(){
                location.href="/jumpPage/jumpPage?page=goods";
                alert("新增成功")
            }
        })
    }
</script>
</html>